<!-- 送回详情 -->
<template>
	<ListLayout :showSlotFooter="routerParams.state != 8">
		<Tips :leftText="Time" :rightText="routerParams.text" :color="routerParams.color[routerParams.state]"> </Tips>
		<!-- 配送中-送回信息 -->
		<template v-if="Object.keys(ReturnInfo).length">
			<ReturnCard :returnInfo="ReturnInfo" :state="routerParams.state"></ReturnCard>
		</template>
		<template v-if="ShowUnable">
			<!-- 无法维修信息 -->
			<template v-if="Object.keys(UnableInfo).length">
				<UnableRepairDetailCard :unableInfo="UnableInfo"></UnableRepairDetailCard>
			</template>
		</template>


		<template v-if="!ShowUnable">
			<!-- 配送中-维修情况 -->
			<template v-if="Object.keys(MaintenanceInfo).length">
				<MaintenanceCard :maintenanceInfo="MaintenanceInfo"></MaintenanceCard>
			</template>
		</template>
		<!-- 配送中-维修信息 -->
		<template v-if="Object.keys(RepairInfo).length">
			<RepairCard :repairInfo="RepairInfo"></RepairCard>
		</template>

		<template v-if="!ShowUnable">
			<!-- 配送中-其他信息 -->
			<template v-if="Object.keys(InvoiceInfo).length">
				<ReturnOtherCard :invoiceInfo="InvoiceInfo"></ReturnOtherCard>
			</template>
		</template>

		<!-- 审核信息 -->
		<template v-if="Object.keys(ReviewInfo).length">
			<ReviewDetailCard :reviewInfo="ReviewInfo"></ReviewDetailCard>
		</template>


		<!-- 配送中-报价信息 -->
		<template v-if="Object.keys(FactoryQuoteInfo).length">
			<OfferDetailCard :quoteInfo="FactoryQuoteInfo"></OfferDetailCard>
		</template>
		<!-- 配送中-科室信息 -->
		<template v-if="Object.keys(SendRepairInfo).length">
			<DepartmentDetailCard :sendRepairInfo="SendRepairInfo"></DepartmentDetailCard>
		</template>
		<!-- 配送中-设备信息 -->
		<template v-if="Object.keys(SendRepairInfo).length">
			<DeviceCard :sendRepairInfo="SendRepairInfo"></DeviceCard>
		</template>
		<!-- 配送中-其他信息[故障信息] -->
		<template v-if="Object.keys(SendRepairInfo).length">
			<FaultCard :sendRepairInfo="SendRepairInfo"></FaultCard>
		</template>


		<template #footer>
			<HButtonGroup @leftClick="onCancel" @rightClick="onService">
				<template #left>
					取消
				</template>
				<template #right>
					送达
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>
</template>

<script>
	import Tips from '@/components/tips/orderTips.vue'
	import ListLayout from '@/components/layout/listLayout.vue'
	import UnableRepairDetailCard from '@/components/card/sendRepair/department/info/unableRepairDetail.vue'
	import ReturnCard from '@/components/card/sendRepair/factory/info/return.vue'

	import MaintenanceCard from '@/components/card/sendRepair/department/info/maintenance.vue'
	import RepairCard from '@/components/card/sendRepair/factory/info/repair.vue'
	import ReturnOtherCard from '@/components/card/sendRepair/factory/info/return-other.vue'
	import ReviewDetailCard from '@/components/card/sendRepair/factory/info/reviewDetail.vue'
	import OfferDetailCard from '@/components/card/sendRepair/department/info/offerDetail.vue'
	import DepartmentDetailCard from '@/components/card/sendRepair/department/info/departmentDetail.vue'
	import DeviceCard from '@/components/card/sendRepair/factory/info/device.vue'
	import FaultCard from '@/components/card/sendRepair/factory/info/fault.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import HButtonBetween from '@/components/buttonGroup/optionButtonGroup.vue'
	import ReapirApi from '@/apis/repair.js'
	import { factoryState } from '@/sendRepair/factory/state.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	export default {

		components: {
			Tips,
			ListLayout,
			ReturnCard,
			UnableRepairDetailCard,
			MaintenanceCard,
			OfferDetailCard,
			DepartmentDetailCard,
			DeviceCard,
			FaultCard,
			RepairCard,
			ReviewDetailCard,
			ReturnOtherCard,
			HButtonGroup,
			HButtonBetween
		},
		computed: {
			Time() {
				let time = this.ReturnInfo?.createTime || this.SendRepairInfo.createTime
				return `派单时间:${time}`
			},
			// 无法维修的显示控制
			ShowUnable() {
				return this.routerParams.source == factoryState.CardSourceState.FactoryCantNotRepair
			},
			UnableInfo() {
				let { cantRepairVo } = this.data;
				if (cantRepairVo != null) {

					return {
						deviceStateToName: cantRepairVo?.deviceStateToName || '',
						deviceDataToName: cantRepairVo?.deviceDataToName || '',
						remark: cantRepairVo?.remark || '',
						enclosure: cantRepairVo?.enclosure || '',
					}
				}
				return {}
			},
			HiddenReturnInfoCard() {
				let { ToBeConfirmedToReturnToTheDepartment } = factoryState.stateValue
				return !(ToBeConfirmedToReturnToTheDepartment == this.routerParams.state)
			},

			// 送回信息
			ReturnInfo() {
				let { sendDeptResultVo } = this.data
				return sendDeptResultVo || {}
			},
			// 维修情况
			MaintenanceInfo() {
				let { finishRepairResultVo } = this.data
				if (finishRepairResultVo != null) {

					return {
						deviceStateToName: finishRepairResultVo?.deviceStateToName,
						deviceDataToName: finishRepairResultVo?.deviceDataToName,
						faultReason: finishRepairResultVo?.faultReason,
						process: finishRepairResultVo?.process,
						enclosure: finishRepairResultVo?.enclosure
					}
				}
				return {}
			},
			// 维修信息 
			RepairInfo() {
				let { finishRepairResultVo } = this.data
				return finishRepairResultVo?.repairMaintenanceItems || []
			},
			// 其他信息
			InvoiceInfo() {
				let { finishRepairResultVo } = this.data
				if (finishRepairResultVo != null) {
					return {
						invoiceTypeToName: finishRepairResultVo?.invoiceTypeToName || '',
						invoiceNum: finishRepairResultVo?.invoiceNum || '',
						testReportFlag: finishRepairResultVo?.testReportFlag || '',
						warrantyPeriod: finishRepairResultVo?.warrantyPeriod || '',
						warrantyStartTime: finishRepairResultVo?.warrantyStartTime || '',
						enclosure: finishRepairResultVo?.enclosure || '',
						invoiceEnclosure: finishRepairResultVo?.invoiceEnclosure || '',
						testReportEnclosure: finishRepairResultVo?.testReportEnclosure || ''
					}
				}
				return {}
			},
			// 厂家报价信息
			FactoryQuoteInfo() {
				let {
					manufacturerInfoVo
				} = this.data
				return manufacturerInfoVo || {}
			},
			// 	送修信息
			SendRepairInfo() {
				let {
					repairInfo
				} = this.data
				return repairInfo || {}
			},
			// 审核信息
			ReviewInfo() {
				let {
					repairQuoteConfirmVo
				} = this.data
				return repairQuoteConfirmVo || {}
			}

		},
		data() {
			return {
				data: {},
				routerParams: {
					id: '',
					color: factoryState.colors,
					text: '',
					state: '',
					source: ''
				}
			}
		},
		methods: {
			// 取消
			onCancel() {
				wx.navigateBack()
			},
			// 送达
			onService() {
				wx.navigateTo({
					url: `${SendRepairRouterConfig.Factory.SubmitService}?id=${this.routerParams.id}&source=${this.data.source}`
				})
			}
		},
		async onLoad(query) {
			wx.showLoading({
				title: '加载中...',
				mask: true
			})
			const { state, currStateToName, id, source } = query
			this.$set(this.routerParams, 'text', currStateToName)
			this.$set(this.routerParams, 'state', state)
			this.$set(this.routerParams, 'id', id)
			this.$set(this.routerParams, 'source', source)
			let res = await ReapirApi.common.getDetail(id)
			if (res.code === 0) {
				this.data = res.body || {}
				console.log(this.data, '-----this.data-----');
				wx.hideLoading()
			} else {
				wx.hideLoading()
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
